package control
{
//	import flash.events.Event;
//	import flash.net.URLVariables;
//	import mx.controls.Alert;
//	import model.ModelLocator;
//	
//	import mx.rpc.events.ResultEvent;
//	import mx.rpc.http.HTTPService;
//	
//	public class SharePhoto
//	{
//		internal var theModel:ModelLocator = ModelLocator.getInstance();
//		 private var SharePhotoHttp:HTTPService;
//		public function SharePhoto()
//		{
//			SharePhotoHttp = new HTTPService();
//			SharePhotoHttp.url = "http://localhost:8080/" + ModelLocator.WEB + "/servlet/sharePhoto";
//			SharePhotoHttp.addEventListener(ResultEvent.RESULT,SharePhotoResultHandler);
//		}
//		
//		internal function SharePhotoResultHandler(event:ResultEvent):void{
//			if(event.result.Result.STATUS == "Successful"){
//				theModel.dispatchEvent(new Event(ModelLocator.SHAREPHOTO_OK));
//			}else{
//				Alert.show("Already shared~~");
//			}		
//		}
//
//		public function doSharePhoto(photoid:String,username:String):void{
//			var params:URLVariables = new URLVariables();
//			params.photoid = photoid;
//			params.username = username;
//			SharePhotoHttp.send(params);
//		}
//	}
	import flash.events.Event;
	
	import model.ModelLocator;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	public class SharePhoto
	{
		internal var theModel:ModelLocator = ModelLocator.getInstance();
		private var SharePhotoRO:RemoteObject;
		public function SharePhoto()
		{
			SharePhotoRO = new RemoteObject();
			SharePhotoRO.destination="SharePhoto";
			SharePhotoRO.doSharePhoto.addEventListener(ResultEvent.RESULT,SharePhotoResultHandler);
			SharePhotoRO.addEventListener(FaultEvent.FAULT, SharePhotoFaultHandler);
		}
		
		public function doSharePhoto(photoid:String):void
		{
			Alert.show("chai here 2");
			SharePhotoRO.doSharePhoto(photoid,theModel.user.user_id);
		}
		
		internal function SharePhotoResultHandler(event:ResultEvent):void
		{
				//Alert.show("show shared markers Successfully.");
				if( event.result as String == "successful")
				Alert.show("share photo successful");
				else if(event.result as String == "exist")
				Alert.show("already shared");
				//Alert.show(theModel.allSharePhoto[1]['username']);
				theModel.dispatchEvent(new Event(ModelLocator.SHAREPHOTO_OK));
		}
		
		internal function SharePhotoFaultHandler(event:FaultEvent):void
		{
			Alert.show("error occur when show the shared markers");
		}
	}
}